<!--
 * @Author: Aileen的代码仓库 aileen20030308@qq.com
 * @Date: 2025-05-05 15:49:59
 * @LastEditors: Aileen的代码仓库 aileen20030308@qq.com
 * @LastEditTime: 2025-05-05 18:52:00
 * @FilePath: \undefinedc:\Users\admin\IdeaProjects\JAVAEEAdvance\spring-mvc-demo\src\main\resources\static\login.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>登录页面</title>
</head>

<body>
  <h1>用户登录</h1>
  用户名：<input name="userName" type="text" id="userName"><br>
  密码：<input name="password" type="password" id="password"><br>
  <input type="button" value="登录" onclick="login()">

  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
  <script>
    function login() {
      $.ajax({
        url: "/user/login",
        //请求方法
        type:"post",
        data: {
          "userName": $("#userName").val(),
          "password": $("#password").val()
        },
        //验证后端接口的成功与失败
        success: function (result) {
          //返回结果为true进行页面跳转
          if (result) {
            //跳转方式1:
            location.href = "/index.html";
            //跳转方式2:
            //location.assign("/index.html");
            //跳转方式3:
            //location.replace("/index.html");
          } else {
            //密码错误
            alert("密码错误");

          }
        }
      });
    }

  </script>
</body>

</html>